package com.zyy.joseata.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhangyy
 */
@Configuration
@Slf4j
public class JoSeataRabbitListenerConfig {

    @Bean
    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
            SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory connectionFactory) {

        JoSeataRabbitListenerContainerFactory factory = new JoSeataRabbitListenerContainerFactory(new JoSeataRabbitListenerMessageProcess());
        // 消费并发数量
//        factory.setConcurrentConsumers(5);
        // 消费预取数量
//        factory.setPrefetchCount(10);
        // 自定义的消费者标签生成策略
        //factory.setConsumerTagStrategy(queue -> queue + "_" + IPUtils.getHostName() + "_" + UUIDUtils.genKey());
        configurer.configure(factory, connectionFactory);
        return factory;
    }

}

